#ifndef _HEAP_H_
#define _HEAP_H_
//	MIN_HEAP
void MIN_HEAPIFY(int *A,int i, float *val)	
{
        int     left = 2 * i;
        int     right = 2 * i + 1;
        int     smaller, tmp;
        if ( left <= A[0] && val[A[left]] < val[A[i]] )
	        smaller = left;
	else
	        smaller = i;
        if ( right <= A[0] && val[A[left]] < val[A[smaller]] )
	        smaller = right;
	if (smaller != i)	
        {
	        tmp = A[smaller]; A[smaller] = A[i]; A[i] = tmp;
                MIN_HEAPIFY ( A, smaller, val );
	}
}
void HEAP_DECREASE_KEY ( int *A,int i,int key, float *val )	
{
        int     tmp;
        A[i] = key;
        while ( i>1 && val[A[i/2]]>=val[A[i]] )
        {
	        tmp = A[i]; 
                A[i] = A[i/2];
                A[i/2] = tmp;
	        i = i/2;
        }
}
#endif
